define(["jQuery", "kendo","fileUpload","widget"], function ($, kendo,fileUpload,widget) {
    return {
		uploadResultUrlFile:false,
		uploadResultNameFile:false,
		uploadResultUrlIcon:false,
		show : function(){
			var center = App.getAbsoluteCenter();
			$( "#file-upload-dragable-menu").css('left', center.x);
			$( "#file-upload-dragable-menu").css('top', center.y);
			
			$( "#file-upload-dragable-menu").show();
			$("#file_upl_loading").hide();
			$("#file_upload_result_f").html("");
			$("#save_file_upl_button").hide();
			$('#upl-file').fileupload({
				dataType: 'json',
				autoUpload: true,
				replaceFileInput: false,
				add: function(e, data){
				
					$("#file_upl_loading").show();
					// $("#file_upload_result_f").html(data.files[0].name);
					$("#save_file_upl_button").hide();
					
					
					
					data.submit();
				},
				always: function(e, data) {
					$("#file_upl_loading").hide();
					$("#save_file_upl_button").show();
					var result;
					if (data.textStatus == 'parsererror') {  // IE9 fails on upload's JSON response
						result = JSON.parse(data.jqXHR.responseText);
					}else if (data.textStatus == 'success') {
						result = data.result;
					} 
					if (result) {
						// ...perform custom handling...  
						App.upload.uploadResultUrlFile = result.files[0].url;
						App.upload.uploadResultNameFile = result.files[0].name;  
					}
				}
								  
			});	 
			
			
		},
		
        init: function (e) {
			$("#file-upload-dragable-menu").draggable();
			$("#file-upload-dragable-menu").hide();
			
		
			$(".upl-file-tools").click(function() { 
				if(!App.toolboxValidation("tool_upload_file_ico"))
				{
					return
				}
				$(this).addClass('active');
				App.openedTool = $(this);
				App.setEnableFileCreationMode(true); 
			});
				
		
			$(".save-file-button").click(function() {
				if(App.upload.uploadResultUrlFile)
				{
					
					App.openedTool.removeClass('active');
					App.openedTool =false;
					$( "#file-upload-dragable-menu" ).hide();
					//alert(App.upload.uploadResultUrl);
					
					var center = App.getAbsoluteCenter();
					App.addUploadedFile(App.upload.uploadResultUrlFile,App.upload.uploadResultNameFile,App.upload.uploadResultUrlIcon,center.x,center.y);
					App.setEnableFileCreationMode(false);
				}
				else
				{
					alert(App.localize("%file_invalid"));
				}
					
			});
			
			$(".cancel-button-file").click(function() {
				var r=confirm(App.localize("%cancel_confirmation"));
				if (r==true)
				{
					
					App.openedTool.removeClass('active');
					App.openedTool =false;
					$( "#file-upload-dragable-menu" ).hide();
					App.setEnableFileCreationMode(false,"");
				}
				else
				{
					console.log("You pressed Cancel!");
				}
			});
			
			// $(".file-upl-choosen").change(function() {
				// if (document.getElementById('upl-icon').files[0]) {
					// var reader = new FileReader();               
					// reader.onload = function (e) {
						// $('#imagePreview').attr('src',e.target.result); 
					// };               
					// reader.readAsDataURL(document.getElementById('upl-icon').files[0]);
				// }
			// });
			
			
		
		}
	}
});